package com.djakapm.swing.component.table;

import com.djakapm.swing.common.ContainerFactory;

import javax.swing.*;
import java.util.Vector;

public class SpecForTable {
	static void can_create_table_with_rows_and_columns() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		Vector<Vector<Object>> rows = new Vector<Vector<Object>>();
		Vector<Object> row = new Vector<Object>();
		row.addElement("Djaka PM");
		row.addElement("Jl. Sri Putri 4 1735B");
		row.addElement("Software Consultant");
		rows.addElement(row);
		
		row = new Vector<Object>();
		row.addElement("Fucker");
		row.addElement("St. Hell");
		row.addElement("Hell Consultant");
		rows.addElement(row);
		
		JFrame frame = ContainerFactory.newFrame("Rows and Columns");
		frame.getContentPane().add(new JScrollPane(new Table(rows,columns)));
		frame.setVisible(true);
	}
	
	static void can_create_table_with_column_only() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		JFrame frame = ContainerFactory.newFrame("Columns only");
		frame.getContentPane().add(new JScrollPane(new Table(columns)));
		frame.setVisible(true);
	}
	
	static void can_add_row() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Post Name");
		columns.addElement("Post Address");
		columns.addElement("Post Title");
		Table table = new Table(columns);
		JFrame frame = ContainerFactory.newFrame("Add Rows after initialize");
		frame.getContentPane().add(new JScrollPane(table));
		frame.setVisible(true);
		Vector<Object> row = new Vector<Object>();
		row.addElement("XXXXXX");
		row.addElement("YYYYYY");
		row.addElement("ZZZZZZ");
		table.addRow(row);
	}
	
	static void can_add_row_using_fluent_method() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		Table table = new Table(columns);
		JFrame frame = ContainerFactory.newFrame("Add Rows using fluent method");
		frame.getContentPane().add(new JScrollPane(table));
		frame.setVisible(true);
		table
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun");
	}
	
	static void can_add_row_using_fluent_method_partial_column() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		Table table = new Table(columns);
		JFrame frame = ContainerFactory.newFrame("Add Rows using fluent method partial columns");
		frame.getContentPane().add(new JScrollPane(table));
		frame.setVisible(true);
		table
		.addRow("Dadang","Jl. Wakuncar")
		.addRow("Suparman")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun");
	}
	
	
	public static void main(String[] args) {
		SpecForTable.can_create_table_with_rows_and_columns();
		SpecForTable.can_create_table_with_column_only();
		SpecForTable.can_add_row();
		SpecForTable.can_add_row_using_fluent_method();
		SpecForTable.can_add_row_using_fluent_method_partial_column();
	}
}
